package com.swjd.controller;

import com.swjd.dao.TbookDao;
import com.swjd.pojo.Tbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 刘涛
 * @create 2021/10/12 16:28
 */
@Controller
public class TbookController {
    @Autowired
    private TbookDao tbookDao;

    @RequestMapping("/display")
    public String display(Model model) {
        List<Tbook> tbooks = tbookDao.selectList(null);
        model.addAttribute("tbooks", tbooks);
        return "display.htm";
    }

    @RequestMapping("/addbook")
    public String addbook() {
        return "addbook.htm";
    }
    @RequestMapping("/add")
    public String add(String Book_name,String Book_number,String Author,String Publisher,Double Price) {
        Tbook tbook = new Tbook();
        tbook.setBookName(Book_name);
        tbook.setBookName(Book_number);
        tbook.setAuthor(Author);
        tbook.setPublisher(Publisher);
        tbook.setPrice(Price);
        tbookDao.insert(tbook);
        return "redirect:/display";
    }
}
